package org.irri.smta.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "COUNTRY")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Country extends TimestampedAutoIdEntity implements Comparable<Country> {

	private static final long serialVersionUID = 1L;
	
	public static final Long DEFAULT_LOCATION_ID = 3L;

	@NotNull
	@Column(name = "NAME", nullable = false)
	@Size(min = 1, max = 200)
	private String name;

	@NotNull
	@Column(name = "ISO2", nullable = false)
	@Size(min = 2, max = 2)
	private String iso2;

	@NotNull
	@Column(name = "ACTIVE", nullable = false)
	private Boolean active = Boolean.TRUE;

	public Country() {
		super();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = StringUtils.substring(name.trim(), 0, 200);
	}

	public String getIso2() {
		return iso2;
	}

	public void setIso2(String iso2) {
		this.iso2 = StringUtils.substring(iso2.trim(), 0, 2);
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	@Override
	public int compareTo(Country o) {
		if (o != null) {
			return this.iso2.compareTo(o.iso2);
		}
		return 0;
	}

	@Override
	public String toString() {
		return "Country [name=" + name + ", iso2=" + iso2 + ", active="
				+ active + "]";
	}

}
